{include file="public/cate" /}
<div class="layui-container">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md8 content detail">
            <div class="fly-panel detail-box">
                <h1>{$ques.title}</h1>
                <div class="fly-detail-info">
                    <span class="layui-badge layui-bg-green fly-detail-column">{$ques.cname}</span>
                    <span class="layui-badge" style="background-color: #999;">{$ques.status ? '已结' : '未结'}</span>
                    <div class="fly-admin-box" data-id="29518"></div>
                    <span class="fly-list-nums">
                        <a href="#comment">
                            <i class="iconfont" title="回答">&#xe60c;</i>{$ques.reply_num}</a>
                        <i class="iconfont" title="人气">&#xe60b;</i>{$ques.view_num}</span></div>
                <div class="detail-about">
                    <a class="fly-avatar" href="/u/19320000/">
                        <img src="__ROOT__/{$ques.face}" alt="zz_hi_zz"></a>
                    <div class="fly-detail-user">
                        <a href="/u/19320000/" class="fly-link">
                            <cite>{$ques.nickname}</cite></a>
                        <span>{:Ftime($ques.ctime)}</span></div>
                    <div class="detail-hits" id="LAY_jieAdmin" data-id="29518">
                        <span style="padding-right: 10px; color: #FF7200">悬赏：{$ques.kiss}飞吻</span>
                        {if condition="$ques.coid"}
                            <span class="layui-btn layui-btn-xs jie-admin layui-btn-danger" qid={$ques.qid} id="collect" type="collect" data-type="add">取消收藏</span>
                        {else/}
                            <span class="layui-btn layui-btn-xs jie-admin " qid={$ques.qid} id="collect" type="collect" data-type="add">收藏</span>
                        {/if}
                    </div>
                </div>
                <div class="detail-body layui-text photos">
                    {if condition="$ques.ext"}
                    <table class="layui-table">
                        <tbody>
                            <tr>
                                <td>版本：{$ques.ext.project} {$ques.ext.version}</td>
                                <td>浏览器：{$ques.ext.browser}</td></tr>
                        </tbody>
                    </table>
                    {/if}
                    {$ques.content}
                </div>
            </div>
            <div class="fly-panel detail-box" id="flyReply">
                <a name="top"></a>
                <fieldset class="layui-elem-field layui-field-title" style="text-align: center;">
                    <legend>回帖</legend></fieldset>
                <ul class="jieda" id="jieda">
                    {if  condition="$answer"}
                        {volist name='answer' id='row'}
                        <li data-id="118288">
                            <a name="item-1530521593264"></a>
                            <div class="detail-about detail-about-reply">
                                <a class="fly-avatar" href="{:url('index/user/home',['uid'=>$row['uid']])}">
                                    <img src="__ROOT__/{$row.face}" alt="zz_hi_zz"></a>
                                <div class="fly-detail-user">
                                    <a href="{:url('index/user/home',['uid'=>$row['uid']])}" class="fly-link">
                                        <cite>{$row.nickname}</cite></a>
                                </div>
                                <div class="detail-hits">
                                    <span>{:Ftime($row.ctime)}</span></div>
                            </div>
                            <div class="detail-body layui-text jieda-body photos">{$row.content}</div>
                            <div class="jieda-reply">
                                <span class="jieda-zan {$row.zid ? 'zanok' : '' }" rid={$row.rid} type="zan">
                                    <i class="iconfont icon-zan"></i>
                                    <em>{$row.zan_num}</em></span>
                                <span type="reply" nickname="{$row.nickname}" uid="{$row.uid}" class="reply">
                                    <i class="iconfont icon-svgmoban53"></i>回复</span>
                            </div>
                        </li>
                        {/volist}
                    {else/}
                    <li class="fly-none">消灭零回复</li>
                    {/if}
                </ul>
                <div style="text-align: center"></div>
                <a name="comment"></a>
                <div class="layui-form layui-form-pane">
                    <form action="/jie/reply/" method="post">
                        <div class="layui-form-item layui-form-text">
                            <div class="layui-input-block">
                                <textarea id="L_content" name="content" required  placeholder="请输入内容" class="layui-textarea fly-editor" style="height: 100px;"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <input type="hidden" name="qid" value="{$ques.qid}">
                            <button class="layui-btn" lay-filter="reply" lay-submit>提交回复</button></div>
                    </form>
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            {include file="public/hot" /}
            <div class="fly-panel" style="padding: 20px 0; text-align: center;">
                <img src="//cdn.layui.com/upload/2017_8/168_1501894831075_19619.jpg" style="max-width: 100%;" alt="layui">
                <p style="position: relative; color: #666;">微信扫码关注 layui 公众号</p></div>
        </div>
    </div>
    <input type="hidden" id="token" name="__token__" value="{$Request.token}" />
</div>
<script>
//Demo
layui.use(['form','layedit'], function(){
  var form = layui.form;
  var layedit = layui.layedit;


    layedit.set({
      uploadImage: {
        url: '{:url('index/jie/upload')}' //接口url
        ,type: 'post' //默认post
      }
    });

  index = layedit.build('L_content',{height: 100});


  $('#collect').click(function(){

        token = $('#token').val();

        qid = $(this).attr('qid')

        $.post("{:url('index/jie/collect')}", {qid: qid,__token__:token}, function(data, textStatus, xhr) {

            if(data.msg=='收藏成功'){
                $('#collect').addClass('layui-btn-danger').html("取消收藏")
            }else{
                $('#collect').removeClass('layui-btn-danger').html("收藏")

            }
            console.log(data);
            
        },'json');

  })


  $('.jieda-zan').click(function(){

        num = Number($(this).children('em').html())

        that =  $(this)

        rid = $(this).attr('rid')

        $.post("{:url('index/jie/zan')}", {rid: rid}, function(data, textStatus, xhr) {

            if(data.code==0){
                layer.msg(data.msg, function(){});
            }else{

                if(data.msg=='点赞成功'){
                    num++
                    that.addClass('zanok')
                    that.children('em').html(num)
                }else{
                    num--
                    that.removeClass('zanok')
                    that.children('em').html(num)

                }

            }
            console.log(data);
            
        },'json');

  })


  $('.reply').click(function(){

        uid =  $(this).attr('uid');

        location.href = "#comment"

        nickname = $(this).attr('nickname');

        nickname = layedit.getContent(index)+" @"+"<a href='{:url('index/user/home')}?uid="+uid+"'>"+nickname+"</a>&nbsp;";

        layedit.setContent(index,nickname)

  })

  form.on('select(cate)', function(data){
      if(data.value==1){
         $('#LAY_quiz').removeClass('layui-hide')
      }else{
         $('#LAY_quiz').addClass('layui-hide')
      }
    });
  
  //监听提交
  form.on('submit(reply)', function(data){
    // 获取编辑器内容
    data.field.content = layedit.getContent(index)

    console.log(data.field);


    $.ajax({
        url: '{:url('index/jie/reply')}',
        type: 'POST',
        dataType: 'json',
        data: data.field,
    })
    .done(function(res) {
        if(res.code==1){

            layer.alert(res.msg, {icon: 6},function(){
                // location.assign('#top')
                location.href = "#top"
                location.reload()
                layer.closeAll();
            });
        }else{
            layer.msg(res.msg, function(){});
        }
    })
    .fail(function() {
        layer.msg("系统异常，请稍后再试", function(){});
    })

    

    return false;
  });
});
</script>
        